<?php
/**
 * crcl/base
 *
 * Copyright 2013 CRCL - André Sabosch - info@crcl.de
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

namespace crcl\base\template;

interface IAlert
{
  public function setMessage($sMessage);
  public function getMessage();

  public function setType($sType);
  public function getType();
}

class Alert implements IAlert
{
  const TYPE_SUCCESS = 'success';
  const TYPE_INFO = 'info';
  const TYPE_WARNING = 'warning';
  const TYPE_DANGER = 'danger';

  public function setMessage($sMessage)
  {
    $this->sMessage = $sMessage;
  }

  public function getMessage()
  {
    return $this->sMessage;
  }

  public function setType($sType)
  {
    if (in_array($sType, $this->aAllowedTypes))
    {
      $this->sType = $sType;
    }
    else
    {
      throw new Exception(Exception::ERROR_ALERT_INVALIDTYPE, array('type' => $sType));
    }
  }

  public function getType()
  {
    return $this->sType;
  }
  /** PRIVATE *************************************************************************************/

  private $sMessage = '';
  private $sType = 'info';

  private $aAllowedTypes = array(
    self::TYPE_SUCCESS, self::TYPE_INFO, self::TYPE_WARNING, self::TYPE_DANGER);
}